from rest_framework.response import Response


class SuccessResponse(Response):
    """
    标准响应成功的返回, SuccessResponse(data)或者SuccessResponse(data=data)
    (1)默认code返回2000, 不支持指定其他返回码
    """

    def __init__(self, data=None, msg='success', status=None, template_name=None, headers=None, exception=False,
                 content_type=None,total=1):
        if not data:
            total = 0
        std_data = {
            "code": 200,
            "msg": msg,
            "total": total,
            "rows": data
        }
        super().__init__(std_data, status, template_name, headers, exception, content_type)